Question: 1 -
Which of these keywords is not a part of exception handling?
-
thrown
-
try
-
finally
-
catch
Answer:
thrown
Solution:
Exceptional handling is managed via 5 keywords – try, catch, throws, throw and finally.
Exceptional handling is managed via 5 keywords – try, catch, throws, throw and finally.
Question: 2 -
Which statement is true?
-
Any statement that can throw an Exception must be enclosed in a try block.
-
catch(X x) can catch subclasses of X where X is a subclass of Exception.
-
The Error class is a RuntimeException.
-
Any statement that can throw an Error must be enclosed in a try block.
Answer:
catch(X x) can catch subclasses of X where X is a subclass of Exception.
Solution:
Option "catch(X x) can catch subclasses of X where X is a subclass of Exception." is correct. If the class specified in the catch clause does have subclasses, any exception object that subclasses the specified class will be caught as well. Option B is wrong. The error class is a subclass of Throwable and not Runtime Exception. Option C is wrong. You do not catch this class of error. Option D is wrong. An exception can be thrown to the next method higher up the call stack.
Option "catch(X x) can catch subclasses of X where X is a subclass of Exception." is correct. If the class specified in the catch clause does have subclasses, any exception object that subclasses the specified class will be caught as well. Option B is wrong. The error class is a subclass of Throwable and not Runtime Exception. Option C is wrong. You do not catch this class of error. Option D is wrong. An exception can be thrown to the next method higher up the call stack.
Question: 3 -
Which of these keywords must be used to handle the exception thrown by try block in some rational manner?
-
throw
-
try
-
catch
-
finally
Answer:
catch
Solution:
If an exception occurs within the try block, it is thrown and cached by catch block for processing.
If an exception occurs within the try block, it is thrown and cached by catch block for processing.
Question: 4 -
When does Exceptions in Java arises in code sequence?
-
None of the mentioned
-
Can Occur Any Time
-
Compilation Time
-
Run Time
Answer:
Run Time
Solution:
Exceptions in Java are run-time errors.
Exceptions in Java are run-time errors.
Question: 5 -
Which of these keywords must be used to monitor for exceptions?
-
catch
-
throw
-
finally
-
try
Answer:
try
Solution:
Try keywords must be used to monitor for exceptions.
Try keywords must be used to monitor for exceptions.